// 数组降维
const arr = [
  {
    id: 1,
    name: 'zs'
  },
  {
    id: 2,
    name: 'ls',
    children: [
      {
        id: 3,
        name: 'ww'
      },
      {
        id: 4,
        name: 'zl',
        children: [
          {
            id: 5,
            name: 'tq',
            children: [
              {
                id: 6,
                name: 'wb'
              }
            ]
          }
        ]
      }
    ]
  },
  {
    id: 7,
    name: 'xx'
  }
]

const func = (arr, tempArr = []) => {
  const result = tempArr

  for (let i = 0; i < arr.length; i++) {
    if (arr[i].children) {
      const { children, ...obj } = arr[i]
      result.push(obj)
      func(children, result)
    } else {
      result.push(arr[i])
    }
  }

  return result
}

console.log(func(arr))
